	
	* Project: Third Party Presence & the Political Salience of Ethnicity in Survey Data
	* Activity: Replication dofile for Sensitivity analysis
	* Time: February 2023
	
	clear all
	set more off
	
	* We setup global
	
	global data "/Users/mashailmalik/Dropbox/Projects/USIP elections/Final Data/USIP Data/Replication folder/usedata"
	global output "/Users/mashailmalik/Dropbox/Projects/USIP elections/Final Data/USIP Data/Replication folder/output"
	
	ssc install sensemakr, replace all
	ssc install texdoc, replace all
	
	* We import the analysis dataset
	
	import delimited using "$data/analysis_dataset.csv", clear varn(1)
	
	* We need to turn string data into num
	
	destring econ fear_violence ethnic_party e_interests parties_genuine vote_coethnic harmony_poss felt_disc age female college a_victim, replace force
	
	* We run the sensitivity analysis
	
	local x = 1
	
	sensemakr econ others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	local x = 2
	
	sensemakr fear_violence others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	local x = 3
	
	sensemakr ethnic_party others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	local x = 4
	
	sensemakr e_interests others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	local x = 5
	
	sensemakr parties_genuine others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	local x = 6
	
	sensemakr vote_coethnic others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	local x = 7
	
	sensemakr harmony_poss others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	local x = 8
	
	sensemakr felt_disc others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others)
	
	local e`x'_1 = string(`e(treat_coef)',"%9.4fc")
	local e`x'_2 = string(`e(treat_se)',"%9.4fc")
	local e`x'_3 = `e(treat_coef)'/`e(treat_se)'
	local e`x'_3 = string(`e`x'_3',"%9.4fc")
	local e`x'_4 = string(`e(r2yd_x)',"%9.4fc")
	local e`x'_5 = string(`e(rv_q)',"%9.4fc")
	local e`x'_6 = string(`e(rv_qa)',"%9.4fc")
	
	
	* We create the tables concerning the results of the main indices
	
	texdoc init "$output/tables/tableE5_statav.tex", replace force
	tex \begin{table}[ht]
	tex \centering
	tex \caption{Table E5: Sensitivity Analysis} 
	tex \begin{tabular}{rrrrrrr}
	tex \hline
	tex & Coef. & S.E. & t(H0) & R2Y\~{}D$|$X & RV\_q & RV\_qa \\ 
	tex \hline
	tex Economic Conditions Worse & `e1_1' & `e1_2' & `e1_3' & `e1_4' & `e1_5' & `e1_6' \\ 
	tex Fear Ethnic Violence & `e2_1' & `e2_2' & `e2_3' & `e2_4' & `e2_5' & `e2_6' \\ 
	tex Support Ethnic Party & `e3_1' & `e3_2' & `e3_3' & `e3_4' & `e3_5' & `e3_6' \\ 
	tex Material Interests & `e4_1' & `e4_2' & `e4_3' & `e4_4' & `e4_5' & `e4_6' \\ 
	tex Genuine Violence & `e5_1' & `e5_2' & `e5_3' & `e5_4' & `e5_5' & `e5_6' \\ 
	tex Vote Coethnic & `e6_1' & `e6_2' & `e6_3' & `e6_4' & `e6_5' & `e6_6' \\ 
	tex Harmony Possible & `e7_1' & `e7_2' & `e7_3' & `e7_4' & `e7_5' & `e7_6' \\ 
	tex Felt Discrimination & `e8_1' & `e8_2' & `e8_3' & `e8_4' & `e8_5' & `e8_6' \\ 
	tex \hline
	tex \end{tabular}
	tex \end{table}
	texdoc close
	
	* Figures
	
	sensemakr econ others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others) benchmark(female) contourplot
	graph save "$output/figures/figure2E1_statav.gph", replace
	
	sensemakr econ others age female college muhajir coenum gender_mismatch large_fam a_victim, treat(others) benchmark(female) tcontourplot
	graph save "$output/figures/figure2E2_statav.gph", replace
	
	
	
	
